package cn.youframe.frame.ctrl;

import cn.youframe.frame.base.YFBase;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * User: Administrator
 * DateTime: 12-7-2: 下午2:43
 */
public class MyInteceptor implements HandlerInterceptor,YFBase {
    private long handleTime=0l;
    @Override
    public void afterCompletion(HttpServletRequest httpServletRequest, HttpServletResponse response, Object o, Exception e) throws Exception {
//        logger.info("afterCompletion");
    }

    @Override
    public boolean preHandle(HttpServletRequest httpServletRequest, HttpServletResponse response, Object o) throws Exception {
        handleTime=System.currentTimeMillis();
        logger.info("preHandle:{} , {}?"+httpServletRequest.getQueryString(),httpServletRequest.getMethod(),httpServletRequest.getRequestURI());
        return true;
    }

    @Override
    public void postHandle(HttpServletRequest httpServletRequest, HttpServletResponse response, Object o, ModelAndView modelAndView) throws Exception {
        handleTime=System.currentTimeMillis()-handleTime;
        if(handleTime>1000){
            logger.warn("preHandle:{} , {}?"+httpServletRequest.getQueryString()+",运行时间达到:"+handleTime+"ms",httpServletRequest.getMethod(),httpServletRequest.getRequestURI());
        }
    }
}
